home *** CD-ROM | disk | FTP | other *** search
/ PC World 2008 February (DVD) / PCWorld_2008-02_DVD.iso / v cisle / PHP / PHP.exe / EasyPHP-2.0b1-setup.exe / {app} / sqlitemanager / include / common.lib.php < prev    next >
Encoding:
PHP Script  |  2006-04-18  |  27.1 KB  |  642 lines

  1. <?php
  2. /**
  3. * Web based SQLite management
  4. * Some functions
  5. * @package SQLiteManager
  6. * @author FrΘdΘric HENNINOT
  7. * @version $Id: common.lib.php,v 1.126 2006/04/18 07:18:52 freddy78 Exp $ $Revision: 1.126 $
  8. */
  9.  
  10. /**
  11. * check if SQLite extension is loaded, and if not load it.
  12. */
  13. function CheckExtension($extName) {
  14.     $SQL_SERVER_OS = strtoupper(substr(PHP_OS, 0, 3));
  15.     if($SQL_SERVER_OS == 'WIN') { $preffix= 'php_'; $suffix = '.dll'; }
  16.     elseif($SQL_SERVER_OS == 'NET') { $preffix= 'php_'; $suffix = '.nlm'; }
  17.     elseif(($SQL_SERVER_OS == 'LIN') || ($SQL_SERVER_OS == 'DAR')) { $preffix= ''; $suffix = '.so'; }
  18.     $extensions = get_loaded_extensions();
  19.     foreach ($extensions as $key=>$ext) $extensions[$key] = strtolower($ext);
  20.     if (!extension_loaded($extName) && !in_array($extName, get_loaded_extensions())) {
  21.         if(DEBUG) {
  22.             $oldLevel = error_reporting();
  23.             error_reporting(E_ERROR);
  24.             $extensionLoaded = dl($preffix.$extName.$suffix);
  25.             error_reporting($oldLevel);
  26.         } else {
  27.             $extensionLoaded = @dl($preffix.$extName.$suffix);
  28.         }
  29.         if ($extensionLoaded) {
  30.             return true;
  31.         } else {
  32.             return false;
  33.         }
  34.     } else return true;
  35. }
  36.  
  37. /**
  38. * Display error message
  39. * @param string $message 
  40. */
  41. function displayError($message){
  42.     echo '
  43.     <center>
  44.         <table width="80%" style="border: 1px solid red;" class="error">
  45.             <tr><td align="center"><b>'.$GLOBALS['traduct']->get(9).' :</b></td></tr>
  46.             <tr><td align="left"><span style="color: red"><b>'.$message.'</b></span></td></tr>
  47.         </table>
  48.     </center>';
  49.     return;
  50. }
  51.  
  52. /**
  53. * return the condition
  54. */
  55. function displayCondition($authType){
  56.     global $SQLiteManagerAuth;
  57.     return (!WITH_AUTH || (
  58.                             isset($SQLiteManagerAuth) &&  $SQLiteManagerAuth->getAccess($authType)
  59.                             ));
  60.  }
  61.  
  62. /**
  63. * Get plugins array
  64. */
  65. function getPlugins(){
  66.     $res = array();
  67.     if ($dir = @opendir('plugins')) {
  68.         while ($element = readdir($dir)) {
  69.             if (substr($element,0,1) != '.' && $element!='CVS')
  70.                 if (is_dir('plugins/'.$element))
  71.                     $res[] = 'plugins/'.$element.'/';
  72.         }
  73.         closedir($dir);
  74.     } 
  75.     return $res;
  76. }
  77.  
  78. /**
  79. * Display the global menu on the right pan, it' dependant of context
  80. */
  81. function displayMenuTitle(){
  82.     global $SQLiteManagerAuth, $workDb;
  83.     $linkBase = 'main.php?dbsel='.$GLOBALS['dbsel'];
  84.     foreach($GLOBALS['dbItems'] as $Items) if(isset($GLOBALS[strtolower($Items)])) $linkBase .= '&'.strtolower($Items).'='.$GLOBALS[strtolower($Items)];
  85.     $out = '';
  86.     
  87.     $menuItems[] = array('txt'=> $GLOBALS['traduct']->get(72),'url'=> $linkBase.'&action=properties');
  88.     if(isset($GLOBALS['table']) && ($GLOBALS['table']!='')){
  89.  
  90.         if(isset($_REQUEST['currentPage'])) $valCurrent = $_REQUEST['currentPage'];
  91.         else $valCurrent = $GLOBALS['action'];
  92.  
  93.         $Context='Table';
  94.         //Items : txt:Text, url:Link, enabled, type, hint, confirm, ...
  95.         $menuItems[] = array('txt'=> $GLOBALS['traduct']->get(73),'url'=> $linkBase.'&action=browseItem');
  96.         $menuItems[] = array('txt'=> $GLOBALS['traduct']->get(74),'url'=> $linkBase.'&action=sql', 'enabled'=> (displayCondition('execSQL')));
  97.         $menuItems[] = array('txt'=> $GLOBALS['traduct']->get(206),'url'=> $linkBase.'&action=select');
  98.         $menuItems[] = array('txt'=> $GLOBALS['traduct']->get(75),'url'=> $linkBase.'&action=insertElement¤tPage='.$valCurrent, 'enabled'=> (displayCondition('data') &&  !$workDb->isReadOnly()));
  99.         $menuItems[] = array('txt'=> $GLOBALS['traduct']->get(222),'url'=> $linkBase.'&action=operation', 'enabled'=> (displayCondition('properties')));
  100.         $menuItems[] = array('txt'=> $GLOBALS['traduct']->get(76),'url'=> $linkBase.'&action=export', 'enabled'=> (displayCondition('export')));
  101.         $menuItems[] = array('txt'=> $GLOBALS['traduct']->get(77),'url'=> $linkBase.'&action=empty', 'confirm'=> $GLOBALS['traduct']->get(79), 'enabled'=> (displayCondition('empty') &&  !$workDb->isReadOnly()));
  102.         $menuItems[] = array('txt'=> $GLOBALS['traduct']->get(15),'url'=> $linkBase.'&action=delete', 'confirm'=> $GLOBALS['traduct']->get(80), 'enabled'=> (displayCondition('del') &&  !$workDb->isReadOnly()));
  103.         
  104.     } elseif(isset($GLOBALS['view']) && ($GLOBALS['view']!='')) {
  105.  
  106.         $Context='View';
  107.         $menuItems[] = array('txt'=> $GLOBALS['traduct']->get(73),'url'=> $linkBase.'&action=browseItem');
  108.         $menuItems[] = array('txt'=> $GLOBALS['traduct']->get(74),'url'=> $linkBase.'&action=sql', 'enabled'=> (displayCondition('execSQL')));
  109.         $menuItems[] = array('txt'=> $GLOBALS['traduct']->get(206,'Select'),'url'=> $linkBase.'&action=select', 'enabled'=> (displayCondition('execSQL')));
  110.         $menuItems[] = array('txt'=> $GLOBALS['traduct']->get(76),'url'=> $linkBase.'&action=export', 'enabled'=> (displayCondition('export')));
  111.         $menuItems[] = array('txt'=> $GLOBALS['traduct']->get(81),'url'=> $linkBase.'&action=add', 'enabled'=> (displayCondition('properties')));
  112.         $menuItems[] = array('txt'=> $GLOBALS['traduct']->get(15),'url'=> $linkBase.'&action=delete', 'confirm'=> $GLOBALS['traduct']->get(82), 'enabled'=> (displayCondition('del') &&  !$workDb->isReadOnly()));
  113.  
  114.     } elseif(isset($GLOBALS['function']) && ($GLOBALS['function']!='')) {
  115.  
  116.         $Context='Function';
  117.         $menuItems[] = array('txt'=> $GLOBALS['traduct']->get(74),'url'=> $linkBase.'&action=sql', 'enabled'=> (displayCondition('execSQL')));
  118.         $menuItems[] = array('txt'=> $GLOBALS['traduct']->get(76),'url'=> $linkBase.'&action=export', 'enabled'=> (displayCondition('export')));
  119.         $menuItems[] = array('txt'=> $GLOBALS['traduct']->get(81),'url'=> $linkBase.'&action=add', 'enabled'=> (displayCondition('properties')));
  120.         $menuItems[] = array('txt'=> $GLOBALS['traduct']->get(15),'url'=> $linkBase.'&action=delete', 'confirm'=> $GLOBALS['traduct']->get(78), 'enabled'=> (displayCondition('del') &&  !$workDb->isReadOnly()));
  121.  
  122.     } elseif(isset($GLOBALS['trigger']) && ($GLOBALS['trigger']!='')) {
  123.  
  124.         $Context='Trigger';
  125.         $menuItems[] = array('txt'=> $GLOBALS['traduct']->get(74),'url'=> $linkBase.'&action=sql', 'enabled'=> (displayCondition('execSQL')));
  126.         $menuItems[] = array('txt'=> $GLOBALS['traduct']->get(81),'url'=> $linkBase.'&action=add', 'enabled'=> (displayCondition('properties')));
  127.         $menuItems[] = array('txt'=> $GLOBALS['traduct']->get(15),'url'=> $linkBase.'&action=delete', 'confirm'=> $GLOBALS['traduct']->get(83), 'enabled'=> (displayCondition('del') &&  !$workDb->isReadOnly()));
  128.  
  129.     } else {
  130.  
  131.         $Context='Database';
  132.         $hintContext = html_entity_decode($GLOBALS['traduct']->get(131), ENT_NOQUOTES, $GLOBALS['charset']);
  133.         $menuItems[] = array('txt'=> $GLOBALS['traduct']->get(84),'url'=> $linkBase.'&action=options');
  134.         $menuItems[] = array('txt'=> $GLOBALS['traduct']->get(74),'url'=> $linkBase.'&action=sql', 'enabled'=> (displayCondition('execSQL')));
  135.         $menuItems[] = array('txt'=> $GLOBALS['traduct']->get(76),'url'=> $linkBase.'&action=export', 'enabled'=> (displayCondition('export')));
  136.         $menuItems[] = array('txt'=> $GLOBALS['traduct']->get(15),'url'=> $linkBase.'&action=del', 'confirm'=> $GLOBALS['traduct']->get(85), 'enabled'=> (displayCondition('del')));
  137.  
  138.     }
  139.     if (!isset($hintContext)) $hintContext = $GLOBALS['itemTranslated'][$Context];
  140.  
  141.     if(ALLOW_EXEC_PLUGIN){
  142.         $plugins = getPlugins();
  143.         foreach($plugins as $plugin_path) {
  144.             $plugin_menu = array();
  145.             include_once($plugin_path.'plugin.php');
  146.             if (@$plugin_menu[$Context]) {
  147.                 $menu = 'plugin_'.$Context.'Menu';
  148.                 $pluginItems = @$$menu;
  149.                 if (isset($pluginsItems) && @count($pluginsItems))
  150.                     foreach ($pluginsItems as $key=>$item) 
  151.                         if (array_key_exists('hint',$item)) 
  152.                             $pluginItems[$key]['hint'] = $hintContext.' : '.$plugin_name.' : '.$item['hint'];
  153.                         elseif (isset($item['txt']))
  154.                             $pluginItems[$key]['hint'] = $hintContext.' : '.$plugin_name.' : '.$item['txt'];
  155.                 if (isset($pluginItems))
  156.                     foreach ($pluginItems as $item) $pluginsItems[] = $item;
  157.             }
  158.         }
  159.       
  160.         if (isset($pluginsItems)) {
  161.             $menuItems[] = array('type'=>'_cmSplit');
  162.             $menuItems[] = array('type'=>'folder', 'txt'=> $GLOBALS['traduct']->get(211,'Plugins'), 'url'=>'#');
  163.             foreach ($pluginsItems as $item) $menuItems[] = $item;
  164.             $menuItems[] = array('type'=>'endfolder');
  165.         }
  166.         $menuItems[] = array('type'=>'_cmSplit');
  167.  
  168.     }    
  169. /* Javascript Menu */
  170.     $out .= "\n\t\t\t".'<script type="text/javascript">'.
  171.           "\n\t\t\t\t".'var jsMenu = [';
  172.   $icon=''; $inFolder='';
  173.     $target='main';
  174.     foreach ($menuItems as $item) {   
  175.       $confirm = '';
  176.       $title = (isset($item['txt']))? $item['txt'] : '';
  177.     $icon = (array_key_exists('icon',$item))?'<img class="seq1" src="'.$item['icon'].'"><img class="seq2" src="'.$item['icon'].'">':' ';
  178.     $description = (array_key_exists('hint',$item))? $item['hint'] : $hintContext.' : '.$title; 
  179.     $description = addslashes(html_entity_decode($description, ENT_NOQUOTES, $GLOBALS['charset']));
  180.         if (!array_key_exists('enabled',$item) || @$item['enabled']) {
  181.             $url = (isset($item['url']))? $item['url'] : '';
  182.             if (isset($item['confirm'])) {
  183.                 $confirm = addslashes(html_entity_decode($item['confirm'], ENT_NOQUOTES, $GLOBALS['charset']));
  184.             }
  185.         } else { 
  186.             $url = '';
  187.             $title = '<i>'.$title.'</i>';
  188.             $description = '[DISABLED] '.$description;
  189.         }
  190.         
  191.         if ($url=='') $url='#';
  192.         $line = "\n\t\t\t\t".$inFolder."['$icon', '$title', '$url', '$target', '$description', '$confirm'";
  193.         
  194.         if (!isset($item['type'])) {
  195.             $line .= '],';
  196.         }
  197.         else
  198.             if ($item['type']=='endfolder') {
  199.                 $out = substr($out,0,strlen($out)-1);
  200.                 $line = "\n\t\t\t\t".'],';
  201.                 $inFolder='';
  202.             } elseif ($item['type']=='folder')
  203.             {
  204.                 $line .= ',';
  205.                 $inFolder .= "\t";
  206.             } else {
  207.                 $line = "\n\t\t\t\t".$item['type'].',';
  208.             }    
  209.     
  210.         $out .= $line;
  211.     }
  212.     $out = substr($out,0,strlen($out)-1);
  213.     global $jsmenu_style;
  214.     if (!isset($jsmenu_style)) $jsmenu_style = 'hbr';
  215.  
  216.     $out .= "\n\t\t\t\t"."];".
  217.   "\n\t\t\t\t"."cmDraw ('CommandMenu', jsMenu, '$jsmenu_style', cmThemeOffice, 'ThemeOffice');".
  218.   "\n\t\t\t"."</script>"."\n\t\t";
  219. /* */
  220.  
  221.   echo '<!-- common.lib.php : displayMenuTitle() -->'."\n";        
  222.     echo '    <div align="center">
  223.         <table class="menu" cellspacing="0" cellpadding="0">
  224.         <tr><td>
  225.         <div id="CommandMenu">'.$out.'</div>
  226.         </td></tr>
  227.         </table>
  228.     </div>';
  229. }
  230.  
  231. /**
  232. * Display pan header
  233. *
  234. * @param string $frame target where the header will be display
  235. * @param bool $withTitle display title
  236. */
  237. function displayHeader($frame, $withTitle=true){
  238.     global $workDb;
  239.     $GlobalTheme = $GLOBALS['localtheme'].'/'.$frame;
  240.     if(is_readable('theme/'.$GLOBALS['localtheme'].'/menu/theme.css'))
  241.         $menuTheme = $GLOBALS['localtheme'];
  242.   else 
  243.       $menuTheme = 'default';
  244.     ?>
  245. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  246. <html>
  247.     <head>
  248.     <title><?php echo $GLOBALS['traduct']->get(3)." ".$GLOBALS['SQLiteVersion'] ?></title>
  249.     <meta http-equiv="Pragma" content="no-cache">
  250.     <meta http-equiv="expires" content="0">
  251.     <meta http-equiv="content-type" content="text/html;charset=<?php echo $GLOBALS['charset'] ?>">    
  252.     <style type="text/css">
  253.     /* to add later in all themes, now can be supersed by theme*/
  254.     table.menu { border-bottom: 1px solid black; width: 80%;}
  255.     table.menuButtons { width: 70%; }
  256.     td.viewPropTitle { border: 1px solid white; }
  257.     td.viewProp {    border: 1px solid white; }
  258.     table.home { width: 90%; text-align: center; }
  259.     td.boxtitle { width: 49%; text-align: center; }
  260.     td.boxtitlespace { width: 2%; font-size:0px; padding:0px; }
  261.     h5 { margin-bottom: 3px; font-size: 12px; }
  262.     table.query { width: 60%; margin-top: 10px; }
  263.     div.BrowseOptions { text-align:left; }
  264.     table.BrowseOption { text-align:left; }
  265.     div.TableOptions { text-align: left; }
  266.     table.Indexes { margin: 5px; width: 70%; border: thin grey solid; text-align: center; }
  267.     body { font-size: 12px; }
  268.   .Tip { font-size: 10px; background-color : Silver; }
  269.   .time { font-size: 10px; float: center }
  270.   div.Rights { border: 1px solid blue; }
  271.     </style>
  272.     <link href="theme/<?php echo $menuTheme?>/menu/theme.css" rel="stylesheet" type="text/css">
  273.     <link href="theme/<?php echo $GlobalTheme?>.css" rel="stylesheet" type="text/css">
  274.     <script src="include/function.js" type="text/javascript" language="javascript"></script>
  275.     <script src="include/JSCookMenu.js" type="text/javascript" language="javascript"></script>    
  276.     <script src="theme/<?php echo $menuTheme?>/menu/theme.js" type="text/javascript" language="javascript"></script>    
  277. <?php
  278. if(isset($GLOBALS['GlobalCalendar'])) echo $GLOBALS['GlobalCalendar']->get_load_files_code() . "\n";
  279. ?>
  280.     </head>
  281.  
  282.     <body>
  283.     <?php
  284.     if( ($frame == 'main') && ($withTitle) && ($GLOBALS['dbsel']) ){
  285.         echo '<h2 class="sqlmVersion">'.$GLOBALS['traduct']->get(131).' : <a href="main.php?dbsel='.$GLOBALS['dbsel'].'" style="text-decoration: none;"><span style="color: red;">'.$GLOBALS['tabInfoDb']['name'].'</span></a>';
  286.         foreach($GLOBALS['dbItems'] as $Items) {
  287.             if(!empty($GLOBALS[strtolower($Items)])) echo ' - '.$GLOBALS['itemTranslated'][$Items].' <a href="main.php?dbsel='.$GLOBALS['dbsel'].'&'.strtolower($Items).'='.$GLOBALS[strtolower($Items)].'" style="text-decoration: none;" target="main"><span style="color: blue;">'.$GLOBALS[strtolower($Items)].'</span></a>';        
  288.         }
  289.         echo '</h2>'."\n";
  290.         if($workDb->isReadOnly()){
  291.             if($workDb->isReadable()) $message = $GLOBALS['traduct']->get(155);
  292.             else $message = $GLOBALS['traduct']->get(232);
  293.             echo '<table width="80%" align="center"><tr><td style="font-size: 10px; border: 1px solid red; color: red; align: center;">'.$message.'</td></tr></table>';
  294.         }
  295.     }
  296. }
  297.  
  298. /**
  299. * Display add form dependent of context
  300. *
  301. * @param string $type represent the context
  302. */
  303. function formAddItem($type){
  304.     switch($type){
  305.         case 'Table':
  306.             echo '    <form name="add'.$type.'" action="main.php" method="POST" target="main">
  307.                     <span style="font-size: 12px;">'.$GLOBALS['traduct']->get(43).' ==> '.$GLOBALS['traduct']->get(19).
  308.                     ' : <input type="text" name="TableName" size="20" class="small-input"> - 
  309.                     <input type="text" name="nbChamps" size="3" class="small-input"> '.$GLOBALS['traduct']->get(44).' 
  310.                     <input class="button" type="submit" value="'.$GLOBALS['traduct']->get(69).'">
  311.                     <input type="hidden" name="dbsel" value="'.$GLOBALS['dbsel'].'">
  312.                     <input type="hidden" name="action" value="add_'.strtolower($type).'">
  313.                     </span>
  314.                     </form>';
  315.             break;
  316.         case 'View':
  317.             echo '<a href="main.php?dbsel='.$GLOBALS['dbsel'].'&action=add_view" class="propItemTitle" target="main"> » '.$GLOBALS['traduct']->get(87).'</a>';
  318.             break;
  319.         case 'Trigger':
  320.             echo '<a href="main.php?dbsel='.$GLOBALS['dbsel'].'&action=add_trigger" class="propItemTitle" target="main"> » '.$GLOBALS['traduct']->get(88).'</a>';
  321.             break;
  322.         case 'Function':
  323.             echo '<a href="main.php?dbsel='.$GLOBALS['dbsel'].'&action=add_function" class="propItemTitle" target="main"> » '.$GLOBALS['traduct']->get(89).'</a>';
  324.             break;
  325.     }
  326. }
  327.  
  328. /**
  329. * Display query has been execute
  330. *
  331. * @param string $query
  332. * @param bool $withLink if true some links will be display
  333. */
  334. function displayQuery($query, $withLink=true, $changesLines=''){
  335.     global $SQLiteManagerAuth; 
  336.     if(empty($query) && isset($GLOBALS['DisplayQuery'])) $query = $GLOBALS['DisplayQuery'];
  337.     $linkBase = 'main.php?dbsel='.$GLOBALS['dbsel'].'&table='.$GLOBALS['table'];
  338.     if($posLim = strpos($query, 'LIMIT')) {
  339.         $queryLink = substr($query, 0, ($posLim-1));
  340.     } else $queryLink = $query;
  341.     if(isset($GLOBALS['DbGrid']) && is_object($GLOBALS['DbGrid'])){
  342.         if(!empty($GLOBALS['DbGrid']->infoNav['start']) || !empty($GLOBALS['DbGrid']->infoNav['end']) || !empty($GLOBALS['DbGrid']->infoNav['all'])){
  343.             $infoNav = '<span style="font-size: 12px">'.$GLOBALS['traduct']->get(136).' '.$GLOBALS['DbGrid']->infoNav['start'].'-'.$GLOBALS['DbGrid']->infoNav['end'].'/'.$GLOBALS['DbGrid']->infoNav['all'].'  </span>';
  344.         }
  345.     }
  346.     if(!isset($infoNav)) $infoNav = '';
  347.     if(WITH_AUTH && isset($SQLiteManagerAuth) &&  !$SQLiteManagerAuth->getAccess('execSQL')) $withLink = false;
  348.     $modifyLink     = '[<a href="'.$linkBase.'&action=sql&sql_action=modify&displayResult=&DisplayQuery='.urlencode($queryLink).'" class="titleHeader" target="main">'.$GLOBALS['traduct']->get(14).'</a>]';
  349.     $explainLink     = '[<a href="'.$linkBase.'&action=sql&sql_action=explain&displayResult=1&DisplayQuery='.urlencode($queryLink).'" class="titleHeader" target="main">'.$GLOBALS['traduct']->get(145).'</a>]';
  350.     $replayLink        = '[<a href="'.$linkBase.'&action=sql&displayResult=1&DisplayQuery='.urlencode($queryLink).'" class="titleHeader" target="main">'.$GLOBALS['traduct']->get(223).'</a>]';    
  351.     echo '
  352.         <table class="query" cellspacing="0" align="center">';
  353.     if($changesLines != '') echo '<tr><td bgcolor="#CCCCCC"><span class="sqlsyntaxe"> '.$changesLines.' '.$GLOBALS['traduct']->get(71).'</span></td></tr>';
  354.     echo '        <tr>
  355.                 <td class="queryTitle" bgcolor="'.$GLOBALS['displayQueryTitleColor'].'"  style="white-space: nowrap">
  356.                     '.$GLOBALS['traduct']->get(90).' : '.(($withLink)? '  '.$infoNav.$modifyLink.' '.$explainLink.' '.$replayLink : '' ).'</td></tr>
  357.             <tr><td class="queryBody" bgcolor="'.$GLOBALS['displayQueryBgColor'].'" style="white-space: nowrap"><div class="sqlsyntaxe">'.highlight_query($query).'</div></td></tr>
  358.         </table><br/>
  359.         ';
  360. }
  361.  
  362. /**
  363. * highlight query for a proch future!!
  364. *
  365. * @param string $query SQL command string
  366. */
  367. function highlight_query($query){
  368.     include_once INCLUDE_LIB.'ParsingQuery.class.php';
  369.     $Colorize =& new ParsingQuery($query, 1);
  370.     $Colorize->explodeQuery();
  371.     $Colorize->colorWordList();
  372.     return $Colorize->highlightQuery();
  373. }
  374.  
  375. /**
  376. * Display function list for the insert / modify form
  377. *
  378. * @param string $champ name of the current champ
  379. */
  380. function SQLiteFunctionList($champ, $userDefine=""){
  381.     $out = '<select name="funcs['.$champ.']">'."\n".'
  382.                 <option value="" />'."\n";
  383.     foreach($GLOBALS['SQLfunction'] as $funct) $out .= '<option value="'.$funct.'">'.$funct.'</option>'."\n";    
  384.     $tabUDF = $GLOBALS["workDb"]->functInfo;
  385.     $out .= '<option value="" />'."\n";    
  386.     if(is_array($tabUDF)) foreach($tabUDF as $udfInfo) if($udfInfo['funct_type']==1) $out .= '<option value="'.$udfInfo['funct_name'].'">'.$udfInfo['funct_name'].'</option>';
  387.     $out .= '</select>';
  388.     return $out;
  389. }
  390.  
  391. /**
  392. * Display operator list for the select form
  393. * @author Maurφcio M. Maia <mauricio.maia@gmail.com>
  394. *
  395. * @param string $champ name of the current champ
  396. */
  397. function SQLiteSelectList($champ, $userDefine=""){
  398.     $out = '<select name="operats['.$champ.']">'."\n".'
  399.                 <option value="" />'."\n";
  400.     foreach($GLOBALS['SQLselect'] as $operat) {
  401.         if(($operat != "fulltextsearch") || ALLOW_FULLSEARCH)
  402.         $out .= '<option value="'.$operat.'">'.$operat.'</option>'."\n";
  403.     }
  404.     $out .= '</select>';
  405.     return $out;
  406. }
  407.  
  408. /**
  409. * Display input TYPE for the insert / modify form
  410. *
  411. * @param array $info data info for the current champ
  412. * @param mixed $data current value of the champ
  413. */
  414. function SQLiteInputType($info, $data, $allowDefault=true, $allow_advanced=true){
  415.     static $tabIndex;
  416.     $allowBigger=false;
  417.     if(empty($tabIndex)) $tabIndex = 1;
  418.     if (!$allowBigger)
  419.         if(eregi('CHAR|TEXT|LOB', $info['type'])) {
  420.             preg_match('/\((.*)\)/', $info['type'], $length);
  421.             if(isset($length[1]) && $length[1]){        
  422.                 $maxlength = ' maxlength="'.$length[1].'"';
  423.                 if($length[1]<=20) $maxlength = ' size="'.($length[1]+1).'" '.$maxlength;
  424.             } else $maxlength = ' size="20"';
  425.         } else $maxlength = ' size="20"';
  426.     
  427.     if($allowDefault && $info['notnull'] && ($data == '')){
  428.         if(strstr($info['type'], '(')) {
  429.             $localType = trim(preg_replace('/\(.*\)/', '', $info['type']));
  430.         } else {
  431.             $localType = $info['type'];
  432.         }
  433.         if($info['dflt_value']!= '') $data = $info['dflt_value'];
  434.         elseif(isset($GLOBALS['SQLiteType'][$localType])) $data=$GLOBALS['SQLiteType'][$localType];
  435.     }
  436.     if((strtoupper(substr($info['type'],0,4))!='TEXT') && (strtoupper(substr($info['type'],0,4))!='BLOB')) {
  437.         if(JSCALENDAR_PATH && isset($GLOBALS['GlobalCalendar']) && (($info['type'] == 'DATE') || ($info['type'] == 'DATETIME'))) {
  438.             $id = $GLOBALS['GlobalCalendar']->_gen_id();
  439.             $out = "<input size=\"15\" 
  440.                             id=\"".$GLOBALS['GlobalCalendar']->_field_id($id)."\" 
  441.                             type=\"text\" 
  442.                             class=\"text\" 
  443.                             name=\"valField[".$info['name']."]\" 
  444.                             value=\"".htmlentities($data, ENT_NOQUOTES, $GLOBALS['charset'])."\"".
  445.                             $maxlength." 
  446.                             tabindex=".($tabIndex++).((!$info['notnull'])? " 
  447.                             onChange=\"if(this.value!='') setCheckBox('editElement', 'nullField[".$info['name']."]', false); else setCheckBox('editElement', 'nullField[".$info['name']."]', true);\"" : '' ).">";
  448.             $out .= '<a href="#" id="'. $GLOBALS['GlobalCalendar']->_trigger_id($id) . '">' . '<img align="middle" border="0" src="' . $GLOBALS['GlobalCalendar']->calendar_lib_path . 'img.gif" alt="" /></a>';
  449.     
  450.             $options = array(    'inputField' => $GLOBALS['GlobalCalendar']->_field_id($id),
  451.                                 'button'     => $GLOBALS['GlobalCalendar']->_trigger_id($id));
  452.             if($info['type'] == 'DATETIME') {
  453.                 $GLOBALS['GlobalCalendar']->calendar_options['ifFormat'] = '%Y-%m-%d %H:%M';
  454.                 $GLOBALS['GlobalCalendar']->calendar_options['daFormat'] = '%Y-%m-%d %H:%M';
  455.             } else {
  456.                 $GLOBALS['GlobalCalendar']->calendar_options['ifFormat'] = '%Y-%m-%d';
  457.                 $GLOBALS['GlobalCalendar']->calendar_options['daFormat'] = '%Y-%m-%d';
  458.             }
  459.             $out .= $GLOBALS['GlobalCalendar']->_make_calendar($options);            
  460.         } else {
  461.             $out = "<input type=\"text\" class=\"text\" name=\"valField[".$info['name']."]\" value=\"".htmlentities($data, ENT_NOQUOTES, $GLOBALS['charset'])."\"".$maxlength." tabindex=".($tabIndex++).((!$info['notnull'])? " onChange=\"if(this.value!='') setCheckBox('editElement', 'nullField[".$info['name']."]', false); else setCheckBox('editElement', 'nullField[".$info['name']."]', true);\"" : '' ).">";
  462.         }
  463.     } else {
  464.         if(ADVANCED_EDITOR && $allow_advanced && isset($GLOBALS['spaw_dir']) 
  465.                 && (isset($_COOKIE["SQLiteManager_HTMLon"]) && !$_COOKIE["SQLiteManager_HTMLon"])){
  466.             $GLOBALS["spawEditorByName"][$info['name']] = new SPAW_Wysiwyg("valField[".$info['name']."]", $data, $GLOBALS["langSuffix"], SPAW_TOOLBAR_STYLE, '', (TEXTAREA_NB_COLS*6), (TEXAREA_NB_ROWS*16));
  467.             // Show SPAW Editor
  468.             $out = $GLOBALS["spawEditorByName"][$info['name']]->show();
  469.         } else {
  470.             $out = "<textarea name=\"valField[".$info['name']."]\" cols=".TEXTAREA_NB_COLS." rows=".TEXAREA_NB_ROWS." tabindex=".($tabIndex++).((!$info['notnull'])? " onChange=\"if(this.value!='') setCheckBox('editElement', 'nullField[".$info['name']."]', false); else setCheckBox('editElement', 'nullField[\'".$info['name']."\']', true);\"" : "" ).">".
  471.                    htmlentities($data, ENT_NOQUOTES, $GLOBALS['charset']).
  472.                     '</textarea>';
  473.         }
  474.     
  475.     }
  476.     if(isset($out)) return $out;
  477. }
  478.  
  479. /**
  480. * Return Available language
  481. */
  482. function getAvailableLanguage(){
  483.     $out = "";
  484.     $listLangue = $GLOBALS['langueTranslated'];
  485.     natsort($listLangue);
  486.     while(list($lgId, $lgLib) = each($listLangue)){
  487.         $out .= '<option value="'.$lgId.'"'.(($GLOBALS['currentLangue']==$lgId)? ' selected="selected"' : '' ).'>'.(($GLOBALS['langueTranslated'][$lgId])? $GLOBALS['langueTranslated'][$lgId] : $lgLib).'</option>'."\n";
  488.     }
  489.     return $out;
  490. }
  491.  
  492. /**
  493. * Return available theme
  494. */
  495. function getAvailableTheme(){
  496.     $out = "";
  497.     //natsort($GLOBALS['themeTranslated']);
  498.     while(list($key,$themeId) = each($GLOBALS['availableTheme'])){
  499.         $themeLib = ($GLOBALS['themeTranslated'][$themeId])? $GLOBALS['themeTranslated'][$themeId] : $themeId;
  500.         $out .= '<option value="'.$themeId.'"'.(($GLOBALS['localtheme']==$themeId)? ' selected="selected"' : '' ).'>'.$themeLib.'</option>'."\n";
  501.     }
  502.     return $out;
  503. }
  504.  
  505. /**
  506. * Apply a function from record form
  507. *
  508. * @param string $function the function name
  509. * @param mixed $value paramaters to apply function
  510. */
  511. function applyFunction($function, $value){
  512.     $newValue = $value;
  513.     if(in_array($function, $GLOBALS['SQLfunction'])){
  514.         if($function == 'MD5') $newValue = "php('md5', $value)";
  515.         elseif($function == 'NOW') $newValue = "php('date', 'Y-m-d')";
  516.         else $newValue = strtolower($function)."($value)";
  517.     } else {
  518.         foreach($GLOBALS['workDb']->functInfo as $functInfo) {
  519.             if($function == $functInfo['funct_name']) $newValue = $function."('$value')";
  520.         }
  521.     }
  522.     return $newValue;
  523. }
  524.  
  525. /**
  526. * Convert a hash table to GET url string
  527. *
  528. * @param array $tab table of key=>value
  529. */
  530. function arrayToGet($tab){
  531.     $strOut = array();
  532.     while(list($var, $value) = each($tab)) $strOut[] = $var."=".$value;
  533.     return implode("&", $strOut);    
  534. }
  535.  
  536. /**
  537. * Cleaning field name, remove non authorized caractere
  538. *
  539. * @param string string is the field name
  540. * @param string $allow PCRE representation of caractΦre authorized
  541. */
  542. function cleanFieldName($string, $allow = 'a-z_0-9[[:space:]]'){
  543.     return eregi_replace('[^'.$allow.']', '', trim($string));
  544. }
  545.  
  546. /**
  547. * Return a tab with all position of a caractere
  548. *
  549. * @param string $string haystack string
  550. * @param char $seperation needle string to find
  551. */
  552. function strpos_all($string, $separator){
  553.     static $tabPos=array();
  554.     $pos = strpos($string, $separator);
  555.     if((string)$pos!=""){
  556.     if(count($tabPos)>=1) $addPrec = ($tabPos[count($tabPos)-1] +1);
  557.     else $addPrec = 0;
  558.         array_push($tabPos, ($pos + $addPrec));
  559.         $substring = substr($string, ($pos + 1), (strlen($string) - ($pos+1)) );
  560.         strpos_all($substring, $separator);        
  561.     }
  562.     return $tabPos;
  563. }
  564.  
  565. /**
  566. * Function for error handling
  567. * return PHP error from SQLite error to enhancement error displaying
  568. */
  569. function phpSQLiteErrorHandling($errno, $errstr, $errfile, $errline){
  570.     preg_match('/:(.*)/', $errstr, $errorResult);
  571.     if(isset($errorResult[1])) $GLOBALS['phpSQLiteError'] = $errorResult[1];
  572. }
  573.  
  574. /**
  575. * Create SELECT from array value
  576. *
  577. * @param array $tabData array("ID"=>"VALUE", ...)
  578. * @param string form $varNamevar name
  579. * @param int $varValue value to selected
  580. * @return string HTML out
  581. */
  582. function createSelect($tabData, $varName, $varValue){
  583.     $out = '';
  584.     if(isset($tabData) && !empty($tabData)){
  585.         $out .= '<SELECT name="'.$varName.'">'."\n".'<option value="" />'."\n";
  586.         foreach($tabData as $id=>$value) $out .= '<option value="'.$id.'"'.(($id==$varValue)? ' selected="selected"' : '' ).'>'.$value.'</option>'."\n";
  587.         $out .='</SELECT>'."\n";
  588.     }
  589.     return $out;
  590. }
  591.  
  592. /**
  593. * Send image HTML!
  594. * if exist img filename in theme, this is display also the './pics/'.$filename is display
  595. * @param string $src filename
  596. * @param sring $alt string is display when mouse over
  597. * @param int $border image border size in px
  598. * @param int $width width size in px
  599. * @param int height heigh size in px
  600. * @return string img HTML tag 
  601. */
  602. function displayPics($src, $alt="", $border=0, $width="", $height=""){
  603.     $filename = basename($src);
  604.     if(file_exists('./theme/'.$GLOBALS['localtheme'].'/pics/'.$filename)){
  605.         $imgSrc = './theme/'.$GLOBALS['localtheme'].'/pics/'.$filename;
  606.     } else {
  607.         $imgSrc = './theme/default/pics/'.$filename;
  608.     }
  609.     return '<img src="'.$imgSrc.'" border="'.$border.'" alt="'.$alt.'" title="'.$alt.'"'.(($width)? ' width='.$width : '' ).(($height)? ' height='.$height : '' ).'>';
  610. }
  611.  
  612. /**
  613. *  Add brackets when spaces in objects, remove existing ones for concatenations [table].[col] > [table.col]
  614. *
  615. * @param string $object object with or without bracket
  616. * @return string object with brackets
  617. */
  618. function brackets($object,$type=''){
  619.     $object = ereg_replace('\[|\]','',$object);
  620.     if (strstr($object,' ')) {
  621.         $object = "[$object]";
  622.     }
  623.     return $object;
  624. }
  625.  
  626. /**
  627. *  Add quotes on values, and support for Like '%text%'
  628. *
  629. * @param string $text string value
  630. * @param string $like string add like %
  631. * @return escaped string with quotes
  632. */
  633. function quotes($text,$like=''){
  634.     if (substr($like,0,1)=='%') $text  = '%'+$text;
  635.     if (substr($like,1,1)=='%') $text .= '%'; 
  636.     $out = "'".$GLOBALS['db']->escape($text)."'";
  637.     return $out;
  638. }
  639. ?>
  640.